<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="{{url_for('static',filename='js/jquery.min.js')}}"></script>
    <script src="{{url_for('static',filename='js/bootstrap.min.js')}}"></script>
    <script src="{{url_for('static',filename='js/jquery.dataTables.min.js')}}"></script>
    <link rel="stylesheet" href="{{url_for('static',filename='css/bootstrap.min.css')}}">
    <link rel="stylesheet" href="{{url_for('static',filename='css/jquery.dataTables.min.css')}}">
    <style>
    .button{
        background-color: white;
        color: black;
        border: 2px solid #4CAF50;
    }

    .button:hover {
        background-color: #4CAF50;
        color: white;
    }

    .button[disabled] {
        opacity: 0.6;
        cursor: not-allowed;
    }

    </style>
    <title>Title</title>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
    <div class="navbar-header">
        <a class="navbar-brand" href="#">盯盘宝后台管理系统</a>
    </div>
    <div>
        <ul class="nav navbar-nav">
            <li ><a href="{{ url_for('start_web') }}">首页</a></li>
            <li ><a href="{{ url_for('permission_manage') }}">权限配置</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    管理员{{ session['admin'] if session['admin'] else "未登录" }}
                    <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="{{ url_for("login_out") }}">退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
    </div>
</nav>


<div align="center">
    <h3 align="center">长线股票池</h3>
    <div align="center">

    <div class="btn-group btn-group-lg" role="group" aria-label="...">
        <div class="btn-group" >
          <button id="source-button" type="button" class="btn btn-primary">全部</button>
          <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
          </button>
          <ul class="dropdown-menu">
            <li><a href="#" onclick="selectSource('全部')">全部</a></li>
            <li><a href="#" onclick="selectSource('robot2')">robot2</a></li>
            <li><a href="#" onclick="selectSource('手动加入')">手动加入</a></li>
          </ul>
        </div>

    </div>
</div><br/><br/>
            <div style="margin:auto">
<div id="add-block" align="center">
<div style="width:30%;">
 <div class="input-group">
     <input type="text" class="form-control" id="stock-input" />
     <span class="input-group-addon"><a href="#" onclick="addStock()"><i class="glyphicon glyphicon-plus"> <span>添加(请输入中文名或6位代码)</span></i></a></span>
 </div>
</div>
</div>
</div>
<table id="LongLineStockPool" cellspacing="0" style="border: 1px solid " border="1"  width="80%">
    <thead>
    <tr>
    <th>Row</th>
    <th>股票代码</th>
    <th>股票名称</th>
    <th>入池日期</th>
    <th>来源</th>
    <th>删除</th>
    </tr>
    </thead>
</table>
</div>
<div align="center">
    <h3 align="center">长线股票池布林线买卖点</h3>

<table id="LongLineStockPoolBollBuySellPoint" cellspacing="0" style="border: 1px solid " border="1"  width="80%">
    <thead>
    <tr>
    <th>Row</th>
    <th>股票代码</th>
    <th>股票名称</th>
    <th>买入日期</th>
    <th>买入价格</th>
    <th>卖出日期</th>
        <th>卖出价格</th>
    </tr>
    </thead>
</table>
</div>
<script type="text/javascript" >
    function selectSource(type) {
        $("#user-type-button").text(type);
             if (type == "全部"){
         type = "";
        }
        LongLineStockPool.column(4).search(type).draw();
    }
function addStock() {
        var stock = $("#stock-input").val();
        if (stock== ""){
            alert("请输入股票");
            return;
        }
        $.ajax({
            url: "/addStockForLongLineStockPool",
            async:true,
			type:'POST',
			data:JSON.stringify({'type':'add','stock':stock}),
			dataType:'json',
            success: function (result) {
                var message = result.message;
                alert(message);
                longLineStockPoolData();
            }
        });
}
function del_stock_pool(code) {
        var go=window.confirm("您确定要删除股票 "+code+" 吗?");
        if (go==false){
            return;
        }
        $.ajax({
        url: "/addStockForLongLineStockPool",
        async:true,
        type:'POST',
        data:JSON.stringify({'type':'del','stock':code}),
        dataType:'json',
        success: function (result) {
            var message = result.message;
            alert(message);
            longLineStockPoolData();
        }
    });
}
var LongLineStockPool = null;
var LongLineStockPoolBollBuySellPoint = null;
function longLineStockPoolData(){
    $.ajax({
            url: "/longLineStockPoolData",
            async:true,
            success: function (data) {
                if ($.type(data) == "string"){
                    data = JSON.parse(data);
                }
                if (LongLineStockPool !=null){
                LongLineStockPool.destroy();
                }
                LongLineStockPool = $('#LongLineStockPool').DataTable({
                "ordering": false,
                "info":     false,
                "lengthChange": false,
                "data": data.longLineStockList,
                "columns": [
                    {"data":"id"},
                    { "data": "stock_code" },
                    { "data": "stock_name" },
                    {"data":"in_pool_date"},
                    {"data":"source"},
                    {"data":""}
                ],
                "columnDefs": [
                {
                    "targets": -1,
                    "render": function (data, type, full, meta ) {
                        var stockCode = full["stock_code"];
                        var cell = '<button class="button" type="text" onclick="del_stock_pool(\''+ stockCode  +'\')" >删除</button>';
                        return cell;
                    }
                }
                ]
            });
                if (LongLineStockPoolBollBuySellPoint !=null){
                LongLineStockPoolBollBuySellPoint.destroy();
                }
                LongLineStockPoolBollBuySellPoint = $('#LongLineStockPoolBollBuySellPoint').DataTable({
                "ordering": false,
                "info":     false,
                "lengthChange": false,
                "data": data.longLineStockBuySellList,
                "columns": [
                    {"data":"id"},
                    { "data": "stock_code" },
                    { "data": "stock_name" },
                    {"data":"buy_date"},
                    {"data":"buy_price"},
                    {"data":"sell_date"},
                    {"data":"sell_price"}
                ]
            });
            }
        });

}

longLineStockPoolData();
</script>

<style type="text/css">
    #dataTable table tr:hover td { background-color: palegoldenrod; }
</style>
</body>
</html>